#include <iostream> 

using namespace std;

const int INF = 0x3f3f3f3f;

string str1, str2;
int n;
string strs;

int main()
{
	cin >> n >> str1 >> str2;
	int x, y;
	x = y = INF;
	for(int i = 1; i <= n; i++)
	{
		cin >> strs;
		if(str1 == strs && (abs(x - y) > abs(i - y) || x == INF)) x = i;
		if(str2 == strs && (abs(x - y) > abs(i - x) || y == INF)) y = i;
	}
	cout << x << " " << y << endl;
	if(x == INF || y == INF) cout << -1 << endl;
	else cout << abs(x - y) << endl;
	
	return 0;
}
